package com.benio.ycfdisplayer.imageloader;

import android.graphics.Bitmap;
import android.view.View;

import com.benio.ycfdisplayer.displayer.DisplayListener;
import com.benio.ycfdisplayer.displayer.OnStartListener;
import com.nostra13.universalimageloader.core.assist.FailReason;
import com.nostra13.universalimageloader.core.listener.ImageLoadingListener;

/**
 * Created by benio on 2016/11/3.
 */
class DisplayListenerAdapter implements ImageLoadingListener {

    private DisplayListener mListener;

    public DisplayListenerAdapter(DisplayListener listener) {
        mListener = listener;
    }

    @Override
    public void onLoadingStarted(String imageUri, View view) {
        if (mListener != null && mListener instanceof OnStartListener) {
            ((OnStartListener) mListener).onStart(imageUri, view);
        }
    }

    @Override
    public void onLoadingFailed(String imageUri, View view, FailReason failReason) {
        if (mListener != null) {
            mListener.onFailure(imageUri, view, failReason.getCause());
        }
    }

    @Override
    public void onLoadingComplete(String imageUri, View view, Bitmap loadedImage) {
        if (mListener != null) {
            mListener.onSuccess(imageUri, view, loadedImage);
        }
    }

    @Override
    public void onLoadingCancelled(String imageUri, View view) {

    }
}
